package org.example.lanchain.service;

import org.example.lanchain.bean.AiAssistantStats;
import org.example.lanchain.mapper.AiAssistantStatsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AiAssistantStatsService {
    @Autowired
    private AiAssistantStatsMapper statsMapper;

    public AiAssistantStats getStatsByUserId(Long userId) {
        return statsMapper.getStatsByUserId(userId);
    }

    public void saveOrUpdateStats(AiAssistantStats stats) {
        AiAssistantStats existing = statsMapper.getStatsByUserId(stats.getUserId());
        if (existing == null) {
            statsMapper.insertStats(stats);
        } else {
            stats.setId(existing.getId());
            statsMapper.updateStats(stats);
        }
    }
} 